package com.xiaotu.dao.mysql;


import com.xiaotu.entity.TvDeleteRecordModel;
import com.xiaotu.entity.TvModel;
import com.xiaotu.entity.TvProcessDataModel;
import com.xiaotu.entity.WorksAwardModel;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;

/**
 * @author zhangxiao
 * @create 2021-09-22 16:36
 */
public interface MysqlTvMapper extends BaseMapper<TvModel> {

    @Select("<script>" +
            " SELECT tvid FROM screenwriter.tab_tv_info WHERE tvid IN ( " +
            " <foreach collection='tvids' separator=',' item='v'> " +
            " #{v} " +
            " </foreach> " +
            " ) " +
            "</script>")
    List<Integer> isExist(@Param("tvids") List<Integer> tvids);

    @Update("<script>" +
            " INSERT INTO `screenwriter`.`tab_tv_info`" +
            " (`tvid`, `tvname`, `alias`, `sets`," +
            " `releasetime`, `actor`, `director`, `screenwriter`," +
            " `producer`, `area`, `productioncompany`, `issuingcompany`," +
            " `background`, `introduction`, `imageurl`, `awards`," +
            " `firstplaytime`, `shootaddress`, `original`, `label`," +
            " `showtype`, `subject`, `platform`, `copyright`," +
            " `createtime`, `lastupdatetime`, `tvtype`, `timelength`," +
            " `uniquename`, `repeat`, `feature`, `contacts`," +
            " `email`, `weibourl`, `datastate`, `publisher`," +
            " `superintended`, `issue`, `topic`, `open_wkd`," +
            " `make_status`, `update_log`, `budget`, `gross`," +
            " `sellcompany`, `presenter`, `datasourceid`, baikeurl, doubanurl) " +
            " VALUES " +
            " <foreach collection='list' separator=',' item='v' > " +
            " (#{v.tvid}, #{v.tvname}, #{v.alias}, #{v.sets}," +
            " #{v.releasetime}, #{v.actor}, #{v.director}, #{v.screenwriter}," +
            " #{v.producer}, #{v.area}, #{v.productioncompany}, #{v.issuingcompany}," +
            " #{v.background}, #{v.introduction}, #{v.imageurl}, #{v.awards}," +
            " #{v.firstplaytime}, #{v.shootaddress}, #{v.original}, #{v.label}," +
            " #{v.showtype}, #{v.subject}, #{v.platform}, #{v.copyright}," +
            " #{v.createtime}, #{v.lastupdatetime}, #{v.tvtype}, #{v.timelength}," +
            " #{v.uniquename}, #{v.repeat}, #{v.feature}, #{v.contacts}," +
            " #{v.email}, #{v.weibourl}, #{v.datastate}, #{v.publisher}," +
            " #{v.superintended}, #{v.issue}, #{v.topic}, #{v.open_wkd}," +
            " #{v.make_status}, #{v.update_log}, #{v.budget}, #{v.gross}," +
            " #{v.sellcompany}, #{v.presenter}, #{v.datasourceid},#{v.baikeurl},#{v.doubanurl}) " +
            " </foreach> " +
            "</script>")
    void batchInsert(@Param("list") List<TvModel> insertMysqlList);

    @Update("<script>" +
            " <foreach collection='list' item='v' > " +
            " UPDATE `screenwriter`.`tab_tv_info` SET " +
            " `tvname` = #{v.tvname}, `alias` = #{v.tvname}, `sets` = #{v.sets}, `releasetime` = #{v.releasetime}," +
            " `actor` = #{v.actor}, `director` = #{v.director}, `screenwriter` = #{v.screenwriter}, `producer` = #{v.producer}," +
            " `area` = #{v.area}, `productioncompany` = #{v.productioncompany}, `issuingcompany` = #{v.issuingcompany}, `background` = #{v.background}," +
            " `introduction` = #{v.introduction}, `imageurl` = #{v.imageurl}, `awards` = #{v.awards}, `firstplaytime` = #{v.firstplaytime}," +
            " `shootaddress` = #{v.shootaddress}, `original` = #{v.original}, `label` = #{v.label}, `showtype` = #{v.showtype}," +
            " `subject` = #{v.subject}, `platform` = #{v.platform}, `copyright` = #{v.copyright}, `createtime` = #{v.createtime}," +
            " `lastupdatetime` = #{v.lastupdatetime}, `tvtype` = #{v.tvtype}, `timelength` = #{v.timelength}, `uniquename` = #{v.uniquename}," +
            " `repeat` = #{v.repeat}, `feature` = #{v.feature}, `contacts` = #{v.contacts}, `email` = #{v.email}," +
            " `weibourl` = #{v.weibourl}, `datastate` = #{v.datastate}, `publisher` = #{v.publisher}, `superintended` = #{v.superintended}," +
            " `issue` = #{v.issue}, `topic` = #{v.topic}, `open_wkd` = #{v.open_wkd}, `make_status` = #{v.make_status}," +
            " `update_log` = #{v.update_log}, `budget` = #{v.budget}, `gross` = #{v.gross}, `sellcompany` = #{v.sellcompany}," +
            " `presenter` = #{v.presenter}, `datasourceid` = #{v.datasourceid}," +
            "  baikeurl = #{v.baikeurl},doubanurl = #{v.doubanurl} WHERE `tvid` = #{v.tvid}; " +
            " </foreach> " +
            "</script>")
    void batchUpdate(@Param("list") List<TvModel> updateMysqlList);

    @Delete("DELETE FROM screenwriter.tab_works_award")
    void clearTvAwards();

    @Insert("<script>" +
            " INSERT INTO `screenwriter`.`tab_works_award`" +
            " (`id`, `tvid`, `award_time`, `award_type`," +
            " `award_section`, `award_role`, `award_nominate`, `collect_time`)" +
            " VALUES " +
            " <foreach collection='list' separator=',' item='v' > " +
            " (#{v.id}, #{v.tv_id}, #{v.award_time}, #{v.award_type}," +
            " #{v.award_section}, #{v.award_role}, #{v.award_nominate}, #{v.collect_time}) " +
            " </foreach> " +
            "</script>")
    void batchInsertTvAwards(@Param("list") List<WorksAwardModel> worksAwardModels);

    @Insert("<script>" +
            " INSERT INTO `screenwriter`.`tab_tv_process_data`" +
            " (`tvid`, `platform`, `playcount`, `heat`, `dbscore`, `collecttime`) " +
            " VALUES " +
            " <foreach collection='list' separator=',' item='v' > " +
            " (#{v.tvId}, #{v.platForm}, #{v.playCount}, #{v.heat}, #{v.dbScore}, #{v.collectTime}) " +
            " </foreach> " +
            "</script>")
    void batchInsertTvProcessData(@Param("list") List<TvProcessDataModel> list);

    @Insert("<script>" +
            " INSERT INTO `screenwriter`.`tab_tv_delete_record`" +
            " (`tvid`, `tvname`, `deletereason`, `deletetime`, `lastupdatetime`)" +
            " VALUES " +
            " <foreach collection='list' separator=',' item='v' > " +
            " (#{v.tvid}, #{v.tvname}, #{v.deletereason}, #{v.deletetime}, #{v.lastupdatetime}) " +
            " </foreach> " +
            "</script>")
    void batchInsertDeleteRecord(@Param("list") List<TvDeleteRecordModel> list);

    @Delete("DELETE FROM `screenwriter`.`tab_tv_delete_record`")
    void clearDeleteRecord();

    @Delete(" DELETE screenwriter.tab_tv_info  " +
            "FROM " +
            "  screenwriter.tab_tv_info " +
            "  INNER JOIN ( SELECT t1.tvid FROM screenwriter.tab_tv_info t1 INNER JOIN screenwriter.tab_tv_delete_record t2 ON t1.tvid = t2.tvid ) t4 ON screenwriter.tab_tv_info.tvid = t4.tvid; ")
    void deleteNoUseTv();
}
